package leetcode_day._2022._202201._2131;

import java.util.Arrays;

/**
 * @author yzh
 * @version 1.0
 * @date 2022/2/23 20:18
 * 游戏中弱角色的数量
 * 算法：排序
 * 攻击力降序排序，防御力升序排序
 */
public class _28_1996 {
    public static void main(String[] args) {
        System.out.println(new _28_1996().numberOfWeakCharacters(new int[][]{{5, 5}, {6, 3}, {3, 6}}));
    }

    public int numberOfWeakCharacters(int[][] properties) {
        Arrays.sort(properties, (a, b) -> {
            if (a[0] != b[0]) return b[0] - a[0];
            else return a[1] - b[1];
        });
        int ans = 0, len = properties.length;
        int max = properties[0][1];
        for (int i = 1; i < len; i++) {
            if (properties[i][1] < max) ++ans;
            else max = properties[i][1];
        }
        return ans;
    }

}
